<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: Product.php 2793 2010-05-03 18:48:14Z quanvo $
 */

class Shop_Models_Product extends Tomato_Model_Entity
{
    protected $_properties = array(
        'product_id'                   => null,
        'category_id'                   => null,
        'account_id'                   => null,
        'product_admin_name'         => null,
        'product_price'               => null,
        'product_price_currency'    => null,
        'product_status_of_delivery'=> null,
        'product_quantity'               => null,
        'product_quantity_mode'     => null,
        'product_image'                => null,
        'product_status'            => null,
        'product_created_date'         => null,
        'product_modified_date'     => null,
        'production_duration'     => null,
        'product_bundle'     => null,
        'product_product_id_chain'     => null,
        'enterprise_id'     => null,
        'product_shipping_price_1'     => null,
        'product_shipping_price_2'     => null,
    );
    
    public function getImage($name = '_thumbnail', $size = '90', $isView = true){  
    	
    	$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
    	
    	$defaultImage = null;
    	if($isView){
	    	$lang = Zend_Controller_Front::getInstance()->getRequest()->getParam('lang');    	
	    	$getConfig 	  = Tomato_Config::getConfig();
	    	$noimage = 'noimage'.$size;
	    	$defaultImage = $viewRenderer->view->APP_STATIC_SERVER.'/'.$getConfig->value->products->$noimage->$lang;
    	}        
    	$arr  = explode(',',$this->_properties['product_image']);
		$file = $arr[0];
		$path = str_replace($viewRenderer->view->APP_STATIC_SERVER,getcwd(),$file);
		$file = Tomato_Helper_Helper::checkFile($path, $file, $name);
		$urlImage = $file?$file:$defaultImage;		
		
		return $urlImage;
    }
}
